<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="txt" />
    <button id="btn">搜索</button>
    <ul id="list">
      <li></li>
      <li></li>
      <li></li>
    </ul>
    <script>
      // includes() 返回布尔值，判断是否找到参数字符串。
      var str = 'sdfkasdfhashfkhksd你好时代峰峻lsdjf'
      // str.includes('你好')// true
      if (str.includes('你好')) {
        console.log('存在')
      }
      var arr = ['男装', '女装', '男鞋', '女鞋', '儿童装', '儿童鞋']
      var btn = document.getElementById('btn')
      btn.onclick = function() {
        var txtval = document.getElementById('txt').value //男
        // var reg = new RegExp(txtval, 'g')
        var hstr = ''
        arr.forEach(function(item) {
          if (item.includes(txtval)) {
            hstr += `<li>${item}</li>`
          }
          // if (reg.test(item)) {
          //   hstr += `<li>${item}</li>`
          // }
        })
        var list = document.getElementById('list')
        list.innerHTML = hstr
      }
    </script>
  </body>
</html>
